#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json

class LoadJson:

	def __init__(self):
		print("开始载入示教数据")


	def list_of_groups(self,init_list, children_list_len):
		list_of_groups = zip(*(iter(init_list),) *children_list_len)
		end_list = [list(i) for i in list_of_groups]
		count = len(init_list) % children_list_len
		end_list.append(init_list[-count:]) if count !=0 else end_list
		return end_list

	def LoadActionDataHang(self,Zone1ToSensor):
		jsonPath = './arm_action_group/单向抓取.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,4):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone1ToSensor= self.list_of_groups(TempData,6)
		# print(Zone1ToSensor)
		# TempData.clear()
		return Zone1ToSensor

	def LoadActionDataGripRed(self,Zone1ToSensor):
		jsonPath = './arm_action_group/单向抓取.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(25,34):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone1ToSensor= self.list_of_groups(TempData,6)
		# print(Zone1ToSensor)
		# TempData.clear()
		return Zone1ToSensor

	def LoadActionDataGripGreen(self,Zone1ToSensor):
		jsonPath = './arm_action_group/单向抓取.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(14,25):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone1ToSensor= self.list_of_groups(TempData,6)
		# print(Zone1ToSensor)
		# TempData.clear()
		return Zone1ToSensor

	def LoadActionDataGripBlue(self,Zone1ToSensor):
		jsonPath = './arm_action_group/单向抓取.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(4,14):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone1ToSensor= self.list_of_groups(TempData,6)
		# print(Zone1ToSensor)
		# TempData.clear()
		return Zone1ToSensor


	def LoadActionDataAToSensor(self,ZoneAToSensor):
		jsonPath = './arm_action_group/AToSensor.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,8):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneAToSensor= self.list_of_groups(TempData,6)
		# print(Zone1ToSensor)
		# TempData.clear()
		return ZoneAToSensor

	def LoadActionDataSensorToRed(self,SensorToRed):
		jsonPath = './arm_action_group/SensorToRed.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]	
		num = 0
		for a in range(0,5):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		SensorToRed= self.list_of_groups(TempData,6)
		# print(SensorToRed)
		return SensorToRed


	def LoadActionDataBToSensor(self,ZoneBToSensor):
		jsonPath = './arm_action_group/BToSensor.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,7):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneBToSensor= self.list_of_groups(TempData,6)
		# TempData.clear()
		return ZoneBToSensor

	def LoadActionDataSensorToGreen(self,SensorToGreen):		
		jsonPath = './arm_action_group/SensorToGreen.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0		
		for a in range(0,5):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		SensorToGreen= self.list_of_groups(TempData,6)
		return SensorToGreen

	def LoadActionDataCToSensor(self,ZoneCToSensor):
		jsonPath = './arm_action_group/CToSensor.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,8):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneCToSensor= self.list_of_groups(TempData,6)
		# TempData.clear()
		return ZoneCToSensor

	def LoadActionDataSensorToBlue(self,SensorToBlue):
		jsonPath = './arm_action_group/SensorToBlue.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0		
		for a in range(0,5):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		SensorToBlue= self.list_of_groups(TempData,6)
		return SensorToBlue

	def LoadActionDataAToRed(self,ZoneAToZone1):
		jsonPath = './arm_action_group/存放ATo红框.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,10):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneAToZone1= self.list_of_groups(TempData,6)
		# TempData.clear()
		return ZoneAToZone1

	def LoadActionDataBToGreen(self,ZoneBToZone2):
		jsonPath = './arm_action_group/存放BTo绿框.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,9):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneBToZone2= self.list_of_groups(TempData,6)
		# TempData.clear()
		return ZoneBToZone2

	def LoadActionDataCToBlue(self,ZoneCToZone3):
		jsonPath = './arm_action_group/存放CTo蓝框.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,10):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		ZoneCToZone3= self.list_of_groups(TempData,6)
		# TempData.clear()
		return ZoneCToZone3

	def LoadActionDataRedToA(self,Zone1ToZoneA):
		jsonPath = './arm_action_group/红框ToA区.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,11):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone1ToZoneA= self.list_of_groups(TempData,6)
		# TempData.clear()
		return Zone1ToZoneA

	def LoadActionDataGreenToB(self,Zone2ToZoneB):
		jsonPath = './arm_action_group/绿框ToB区.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,9):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone2ToZoneB= self.list_of_groups(TempData,6)
		# TempData.clear()
		return Zone2ToZoneB

	def LoadActionDataBlueToC(self,Zone3ToZoneC):
		jsonPath = './arm_action_group/蓝框ToC区.json'
		with open(jsonPath,'r') as f:
			data = json.load(f)
		TempData=[]
		num = 0
		# ActionNum = len(data)
		for a in range(0,11):
			for item in data[a]['Cells']:
				for key in item:
					if(num%2==0 ):
						if(num>=1 and num<=12):
							TempData.append(item[key])
					num+=1
			num=0
		Zone3ToZoneC= self.list_of_groups(TempData,6)
		# TempData.clear()
		return Zone3ToZoneC

